package com.yonyou.iuap.corp.demo.yonbip.group;

import com.yonyou.iuap.corp.demo.yonbip.OpenBaseTest;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 群组消息
 * @author: nishch
 * @create: 2021-03-19
 **/
public class Group  extends OpenBaseTest {


    /**
     * 第一步
     * 根据友户通userId批量获取用户mid
     * 这个接口可以获取到 qzid
     * https://open.diwork.com/#/doc-center/docDes/api?code=yonbip&section=dfc912ad-0150-4343-ab2b-71323ac2c582
     * @throws Exception
     */
    @Test
    public void qzid() throws Exception {
        String url = "https://api.diwork.com/yonbip/uspace/batchDoConvert/get_memberIds";
        String[] yhtuserIds = new String[]{
            "0f059088-9c92-4769-a3e7-8f1a341cc3df"
        };
        Map<String, Object> params  = new HashMap<String, Object>();
        params.put("userIds",yhtuserIds);
        baseApi.doPost(url,params);
    }


    /**
     *  第二步
     *  获取用户所在的群组--根据友户通用户ID，分页获取所在内部群
     *  https://open.diwork.com/#/doc-center/docDes/api?code=yonbip&section=d702928f-e407-4409-ae36-e73291129287
     * @throws Exception
     */
    @Override
    public void list() throws Exception {
        String url = "https://api.diwork.com/yonbip/uspace/group/getGroupByYhtUserId";
        Map<String, Object> params  = new HashMap<String, Object>();
        params.put("page",pageIndex);
        params.put("yhtUserId","0f059088-9c92-4769-a3e7-8f1a341cc3df");
        params.put("count",pageSize);
        params.put("keywords","哈");  //群名称like
        baseApi.doPost(url,params);
    }

    /**
     * 向内部群发送文本消息
     * https://open.diwork.com/#/doc-center/docDes/api?code=yonbip&section=3a728de3-11f2-487a-835f-a91091a2f1d7
     * @throws Exception
     */
    @Test
    public void message_muc_text() throws Exception {
        String qzid = "112392";  //第一步返回的结果  固定不变的，获取一次保存即可
        String gid = "71123";   //第二步返回的结果   固定不变的，获取一次保存即可
        String url = "https://api.diwork.com/yonbip/uspace/group/message_muc_text";
        Map<String, Object> params  = new HashMap<String, Object>();
        params.put("content","我来了哦-----");
        params.put("yhtUserId","0f059088-9c92-4769-a3e7-8f1a341cc3df");
        params.put("mucId","group_"+qzid+"_"+gid);
        baseApi.doPost(url,params);
    }


    @Override
    public void detail() throws Exception {

    }

    @Override
    public void save() throws Exception {

    }
}
